package com.itheima.sh.e_arrayList_05;

import java.util.ArrayList;

public class Demo01 {
    public static void main(String[] args) {
        //1.创建ArrayList对象
        ArrayList<String>list=new ArrayList<>();
        //2.使用对象调用ArrayList类中的方法
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("麻六");
        list.add("田七");
        System.out.println("王五");
        //2.1向指定位置的索引，添加索引
        list.add(0,"DK");
        //3.根据索引获取元素
        String s = list.get(1);
        System.out.println("s = " + s);

        //4.获取集合中元素的个数，获取集合的长度
        int size = list.size();
        System.out.println("size = " + size);
        //5.遍历集合
        for (int i = 0; i < list.size(); i++) {
            String s1 = list.get(i);
            System.out.println("s1 = " + s1);
        }
        String remove = list.remove(1);
        System.out.println("remove"+remove);//张三
        for (int i = 0; i < list.size(); i++) {
            String s1 = list.get(i);
            System.out.println("s1 = " + s1);

            //根据元素删除
            boolean boo = list.remove("田七");
            System.out.println("boo = " + boo);
            for (int i1 = 0; i1 < list.size(); i1++) {
                String s2 = list.get(i);
                System.out.println("s2 = " + s2);
            }
        }
    }
}
